<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue.set的使用</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <h2>学校名称：{{name}}</h2>
        <h2>学校地址：{{address}}</h2>
        <h1>校长是：{{school.leader}}</h1>
        <button @click="add">添加一个性别信息</button>
        <h2>学生姓名：{{student.name}}</h2>
        <h2 v-if="student.sex">学生性别：{{student.sex}}</h2>
        <h2>rAge--{{student.age.rAge}},sAge--{{student.age.sAge}}</h2>
        <ul>
            <li v-for="(f,index) in student.friends" :keys="index">
                {{f.name}}---{{f.age}}
            </li>
        </ul>
    </div>
    <script>
        const vm = new Vue({
            el:"#root",
            data:{
                name:'尚硅谷',
                address:'北京',
                school:{
                    
                },
                student:{
                    name:'tom',
                    age:{
                        rAge:40,
                        sAge:20
                    },
                    friends:[
                        {name:'jerry',age:30},
                        {name:'tony',age:32}
                    ]
                }
            },
            methods:{
                add(){
                    Vue.set(this.student,'sex' , '男')
                }
            }
        })
    </script>
</body>
</html>